# delimit ;
clear ;
cd "replication" ;
set more off ; 

* *************************************************************************** ;
* re-run endline analysis
* *************************************************************************** ;

cd ".." ;
do "./replication/do/table04-endline-knowledge-aggregate.do" ; 

* ***************************************************************************** ;
* regressions, robustness check 1: Removing strata fixed effects
* ***************************************************************************** ;

foreach var in module_all module1_know module23_know module4_know module5_know { ;
	
	reg `var' healthonly healthandpay, robust ;
	qui est sto `var'1; 
	
	test healthonly = healthandpay ; 
	estadd local titlerow = "" ; 
	estadd scalar fstat = r(F): `var'1 ; 
	estadd scalar pval = r(p): `var'1 ; 

	summarize `var' if control == 1 & e(sample) == 1;
	estadd scalar cmean = r(mean): `var'1 ; 
	estadd scalar csd = r(sd): `var'1 ;

} ;

* ***************************************************************************** ;
* regressions, robustness check 2: clustered standard errors
* ***************************************************************************** ;

foreach var in module_all module1_know module23_know module4_know module5_know { ;
	
	areg `var' healthonly healthandpay, a(strata) robust cluster(waveclass) ;
	qui est sto `var'2 ; 
	
	test healthonly = healthandpay ; 
	estadd local titlerow = "" ; 
	estadd scalar fstat = r(F): `var'2 ; 
	estadd scalar pval = r(p): `var'2 ; 

	summarize `var' if control == 1 & e(sample) == 1;
	estadd scalar cmean = r(mean): `var'2 ; 
	estadd scalar csd = r(sd): `var'2 ;

} ;

* **************************************************************************
* output results from robustness check 1
* ************************************************************************** ;

esttab module*1 using "./output/appendix-table-alternative-specifications-endline-knowledge-aggregate-panelA.tex",
	replace
	drop(_cons) 
	cells(b(label() star fmt(%9.3f %9.3f)) se(par)) 
	star(* 0.10 ** 0.05 *** 0.01) 
	stats(titlerow fstat pval cmean csd N, fmt(%9s %9.3f %9.3f %9.3f %9.3f %9.0f) labels("\(F\)-test, HEE = HEEC" "$\qquad$ \(F\)-statistic" "$\qquad$ \(p\)-value" "Control Mean" "Control SD" "N"))
	prehead(\begin{table}[htbp] \centering \normalsize `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"'
		\captionsetup{justification=centering} 
		\caption{Effects on Longer-Term Health Knowledge \\ Alternative Regression Specifications}
		\label{appendix-table-alternative-reg-spec-endline}
		\setlength{\tabcolsep}{7.5pt}
		\begin{tabular*}{0.9\linewidth}{p{3.5cm}p{1.5cm}p{1.5cm}p{1.5cm}p{1.5cm}p{1.5cm}}
		\toprule)
	legend label  booktabs  collabels( , none)
	mgroups(
	"All Topics" 
	"By Topic" 
	, pattern(1 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
	posthead(\midrule \end{tabular*}
	\bigskip
	\captionsetup[sub]{justification=raggedleft} 
	\subcaption*{\normalsize Panel A: Removing Strata Fixed Effects} 
	\vspace{-0.5ex}
	\newcolumntype{C}{>{\centering\arraybackslash}X} 
	\setlength{\tabcolsep}{6pt}
	\begin{tabularx}{0.9\linewidth}{lCCCCCC}
	\midrule
	&\multicolumn{1}{c}{(1)} &\multicolumn{1}{c}{(2)} &\multicolumn{1}{c}{(3)}
	&\multicolumn{1}{c}{(4)} &\multicolumn{1}{c}{(5)}
	\\ \midrule)
	postfoot(`"\midrule"'  \end{tabularx}) ;

* **************************************************************************
*  output results from robustness check 2
* ************************************************************************** ;
	
esttab module*2 using "./output/appendix-table-alternative-specifications-endline-knowledge-aggregate-panelB.tex",
	replace nodepvars nomtitles
	drop(_cons)
	eqlabels(none)
	cells(b(label() star fmt(%9.3f %9.3f)) se(par)) 
	star(* 0.10 ** 0.05 *** 0.01) 
	stats(titlerow fstat pval cmean csd N, fmt(%9s %9.3f %9.3f %9.3f %9.3f %9.0f) labels("\(F\)-test, HEE = HEEC" "$\qquad$ \(F\)-statistic" "$\qquad$ \(p\)-value" "Control Mean" "Control SD" "N"))
	prehead(\bigskip
	\subcaption*{\normalsize Panel B: Clustered Standard Errors }
	\vspace{-0.5ex}
	\setlength{\tabcolsep}{6pt}
	\begin{tabularx}{0.9\linewidth}{lCCCCCC}
	\midrule)
	label booktabs collabels( , none)
	postfoot(`"\midrule"'  \end{tabularx}
	\captionsetup{justification=justified, width=0.9\linewidth} 
	\caption*{\footnotesize \textit{Notes:} This table examines the robustness of the results presented in Table \ref{table-endline-knowledge-aggregate} to different regression specifications. Panel A excludes randomization strata fixed effects from the regression. Panel B uses standard errors clustered at the wave-class level. 
	***\$\,p < 0.01$, **\$\,p < 0.05$, *\$\,p<0.10$.
		}
	\end{table}) ;
	

exit ;



